//
//  MyBuyerViewController.m
//  YiFei
//
//  Created by yangyan on 16/9/2.
//  Copyright © 2016年 yous. All rights reserved.
//

#import "MyBuyerViewController.h"
#import "MyBuyerTableViewCell.h"
#import "MyBuyerInfoTableViewCell.h"
#import "MyBuyerAskTableViewCell.h"
@interface MyBuyerViewController ()

@end

@implementation MyBuyerViewController

- (void)setNav {
    UIButton* leftBtn= [UIButton buttonWithType:UIButtonTypeCustom];
    
    [leftBtn setImage:[UIImage imageNamed:@"goback.jpg"] forState:UIControlStateNormal];
    leftBtn.frame = CGRectMake(0, 0, 25, 25);
    UIBarButtonItem* leftBtnItem = [[UIBarButtonItem alloc]initWithCustomView:leftBtn];
    
    [leftBtn addTarget:self action:@selector(leftButtonClick) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem=leftBtnItem;
    
    UIBarButtonItem * rightButton = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(rightButtonClick:)];
    self.navigationItem.rightBarButtonItem=rightButton;
    self.automaticallyAdjustsScrollViewInsets=YES;
}

- (void)rightButtonClick {

}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title=@"我的客户";
    [self setNav];
    self.view.backgroundColor=[UIColor groupTableViewBackgroundColor];
    [self addContentView];
}


-(void)addContentView{
    self.tableV=[[UITableView alloc] initWithFrame:CGRectMake(10, 10, WIDTH-20, HEIGHT-10) style:UITableViewStyleGrouped];
    self.tableV.layer.masksToBounds=YES;
    self.tableV.layer.cornerRadius=4.0;
    self.tableV.delegate=self;
    self.tableV.dataSource=self;
    self.tableV.backgroundColor=[UIColor groupTableViewBackgroundColor];
    
    self.tableV.tableHeaderView.backgroundColor=[UIColor groupTableViewBackgroundColor];
    self.tableV.tableHeaderView.layer.masksToBounds=YES;
    self.tableV.tableHeaderView.layer.cornerRadius=5.0;
    [self.view addSubview:self.tableV];

}

#pragma Mark -- 事件处理
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section==0||section==2) {
        return 30.0;
    }else{
        return 0;
    }
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section==0) {
        return 40;
    }else if (indexPath.section==1){
        return 190;
    }else{
        return 330;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section==0) {
        static NSString *cellIdent=@"cell";
        MyBuyerTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellIdent];
        if (cell==nil) {
            cell=[[MyBuyerTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdent];
        }
        cell.layer.masksToBounds=YES;
        cell.layer.cornerRadius=5.0;
        cell.backgroundColor=[UIColor whiteColor];
        cell.imagV.backgroundColor=[UIColor orangeColor];
        cell.label.text=@"客户C公司的名称";
        return cell;
    }else if (indexPath.section==1){
        static NSString *cellIdent=@"cell2";
        MyBuyerInfoTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellIdent];
        if (cell==nil) {
            cell=[[MyBuyerInfoTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdent];
        }
        cell.layer.masksToBounds=YES;
        cell.layer.cornerRadius=5.0;
        cell.backgroundColor=[UIColor whiteColor];
        return cell;
    }else{
        static NSString *cellIdent=@"cell3";
        MyBuyerAskTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellIdent];
        if (cell==nil) {
            cell=[[MyBuyerAskTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdent];
        }
        cell.layer.masksToBounds=YES;
        cell.layer.cornerRadius=5.0;
        cell.backgroundColor=[UIColor whiteColor];
        return cell;
    }
}


- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UILabel *label=[[UILabel alloc] init];
    [label sizeToFit];
    label.backgroundColor=[UIColor whiteColor];
    label.frame=CGRectMake(0, 0, WIDTH, 30);
    label.textColor=[UIColor blackColor];
    label.textAlignment=NSTextAlignmentCenter;
    label.font=[UIFont systemFontOfSize:16.0];
    if (section==0) {
        label.text=@"  商品参数";
    }if (section==1) {
    }else if(section==2){
        label.text=@"  报价供应商";
    }
    return label;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
